﻿@model IEnumerable<vnMcdonald.Models.Order>

@{
    ViewBag.Title = "monthStatictis";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}

<h2>THỐNG KÊ DANH THU THEO THÁNG</h2>
<h3>Tổng danh thu: <span style="font-size:16px;color:red;">
    @{
        if (ViewBag.total_statictis == null)
	    {
		    ViewBag.total_statictis = 0;
        }        
    } @string.Format("{0:0,0}", ViewBag.total_statictis) VNĐ

                   </span>
</h3>
<div id="ordermenu">
    <ul id="ul-ordermenu">
        <li><a href="@Url.Action("statistic", "Admin")" title="Xem theo ngày">Ngày</a></li>
        <li rel="1" class="order-m-active"><a href="@Url.Action("monthStatictis", "Admin")" title="Xem theo tháng">Tháng</a></li>
        <li><a href="@Url.Action("yearStatictis", "Admin")" title="Xem theo năm">Năm</a></li>
        @Html.TextBox("DateTime",null)
        <input type="button" value="Xem" id="btnstatictis" />
    </ul>
</div>
<div class="clear"></div>
<div id="reloadtable">
<table class="thetable">
    <tr><td colspan="6">
        Tổng tiền: <span style="color:blue;font-weight:bold">@{
        if (ViewBag.total == null)
	    {
		    ViewBag.total = 0;
        }        
    } @string.Format("{0:0,0}", ViewBag.total) VNĐ</span>
        </td>
    </tr>
    <tr>
        <th scope="col" width="5%">STT</th>
        <th scope="col" width="15%">MÃ ĐH</th>
        <th scope="col" width="20%">Tổng Giá(VNĐ)</th>
        <th scope="col" width="20%">Ngày tạo</th>
        <th scope="col" width="30%">Khách hàng</th>
        <th scope="col" width="10%">Tùy chọn</th>
    </tr>
    <tbody id="reloadorder">
        @{
            int i = 0;
            foreach (var item in Model)
            {
                i=i+1;
                <tr>
                    <td class="text-center">@i</td>
                    <td class="text-center">@Html.DisplayFor(modelItem => item.Codes)</td>
                    <td class="text-center">@Html.DisplayFor(modelItem => item.TotalPrice)</td>
                    <td class="text-center">@Html.DisplayFor(modelItem => item.CreateDate).ToString().Substring(0, 10)</td>
                    <td class="text-center">@Html.DisplayFor(modelItem => item.Recipient)</td>
                    <td class="text-center">
                        <a href="@Url.Action("OrderView","admin",new { id=item.OrderId })" title="Xem" class="view"><span>Xem</span></a>
                    </td>
                </tr>
            }
        }
    </tbody>
</table>
</div>
<style>
    .ui-datepicker-calendar
    {
        display:none;
    }
</style>
<script type="text/javascript">
    $(function () {
        $('#btnstatictis').click(function () {
            //alert($("#DateTime").val());
            var date = $("#DateTime").val();
            var stt = $(".order-m-active").attr("rel");
            $.ajax({
                type: 'post',
                url: '/admin/reloadStatistic',
                data: { date: date, stt: stt },
                success: function (data) {
                    $("#reloadtable").empty().append(data);
                }
            });
        });
        $('#DateTime').datepicker({
            dateFormat: "mm/yy",
            changeMonth: true,
            changeYear: true,
            showAnim: "blind",
            yearRange: "-50:+0",
            onClose: function (dateText, inst) {
                var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                $(this).datepicker('setDate', new Date(year, month, 1));
            },
            beforeShow: function (input, inst) {
                var tmp = $(this).val().split('/');
                $(this).datepicker('option', 'defaultDate', new Date(tmp[1], tmp[0] - 1, 1));
                $(this).datepicker('setDate', new Date(tmp[1], tmp[0] - 1, 1));
            }
        });
    });
</script>